<template xmlns:el-col="http://www.w3.org/1999/html">
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 患者信息
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="query.hospitalId" placeholder="医院ID" class="handle-input mr10" @keyup.enter.native="handleSearch"></el-input>
                <el-input v-model="query.ptNm" placeholder="姓名" class="handle-input mr10" @keyup.enter.native="handleSearch"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                <el-button type="el-button" icon="el-icon-delete" @click="handleReset">重置</el-button>
<!--                <div class="right-items" style="float: right;">-->
<!--                    <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新增</el-button>-->
<!--                </div>-->
            </div>
            <el-table
                    :data="tableData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                    @selection-change="handleSelectionChange"
            >
                <el-table-column prop="ptId" label="患者ID" width="200" align="center"></el-table-column>
                <el-table-column prop="ptNm" label="姓名" align="center" width="120"></el-table-column>
<!--                <el-table-column prop="ptWg" label="体重(Kg)" align="center"></el-table-column>-->
<!--                <el-table-column prop="ptRedWg" label="减重值" align="center"></el-table-column>-->
                <el-table-column  prop="ptStateText" label="状态" align="center" width="100"></el-table-column>
                <el-table-column prop="ptCrtBy" label="创建人" align="center" width="120"></el-table-column>
                <el-table-column v-if="false" prop="ptUpdBy" label="更新人" align="center" width="80"></el-table-column>
                <el-table-column prop="ptIstTm" label="插入时间" align="center" sortable></el-table-column>
                <el-table-column v-if="false" prop="ptUpdTm" label="更新时间" align="center"></el-table-column>
                <el-table-column prop="hospitalId" label="医院ID" align="center"></el-table-column>
                <el-table-column prop="hospitalSystemId" label="机器编号" align="center" width="100"></el-table-column>
                <el-table-column  label="操作"  align="center">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                icon="el-icon-view"
                                @click="handleEdit(scope.$index, scope.row)"
                        >查看</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                        background
                        layout="total, prev, pager, next"
                        :current-page="query.pageIndex"
                        :page-size="query.pageSize"
                        :total="pageTotal"
                        @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
        <!-- 更换医生弹出框 -->
        <el-dialog title="更换医生" :visible.sync="replaceDoctorVisible" width="20%" :close-on-click-modal="false">
            <el-form ref="replaceform" :model="replaceform" label-width="100px" >
                <el-form-item label="患者姓名" prop="ptNm" >
                    <el-input disabled v-model="replaceform.ptNm" style="width: 80%"></el-input>
                </el-form-item>

                <el-form-item label="医生信息" prop="userAcct" >
                    <el-select v-model="replaceform.userAcct" placeholder="请选择更换医生" style="width: 80%">
                        <el-option v-for="userAcct in userAccts" :label="userAcct.userNm+'('+userAcct.userAcct+')'" :key="userAcct.userAcct" :value="userAcct.userAcct"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="replaceDoctColse">取 消</el-button>
                <el-button type="primary" @click="saveReplaceDoct">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 开具处方弹出框 -->
        <el-dialog title="开具处方" :visible.sync="prescriptionVisible" width="40%" :close-on-click-modal="false">
            <div style="margin-bottom: 10px;">
                <el-form ref="kjForm" :rules="kjFormRules" :model="kjForm" label-width="80px">
                    <el-row style="margin-top: 10px">
                        <el-col :span="2" style="margin-left: 15px">
                            <el-button style="background-color: #c2e7b0"
                                    @click="addTab(editableTabsValue)"
                            >
                                +
                            </el-button>
                        </el-col>
                        <el-col :span="10">
                            <el-form-item label="治疗师" prop="preCrtBy">
                                <el-select v-model="kjForm.preCrtBy" placeholder="请选择治疗师">
                                    <el-option v-for="crtBy in crtBys" :label="crtBy.userNm+'('+crtBy.userAcct+')'" :key="crtBy.userAcct" :value="crtBy.userAcct"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="训练次数" prop="preTimes" >
                                <el-input type="number" v-model="kjForm.preTimes" :min="1" @keyup.native="proving1"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
            <el-tabs v-model="editableTabsValue" type="card" closable @tab-remove="removeTab">
                    <el-tab-pane v-if="editableTabs && editableTabs.length >=0"
                        v-for="(item, index) in editableTabs"
                        :key="item.name"
                        :label="item.title"
                        :name="item.name">
                       <component :is="item.content"  v-on:formData="handleFormData" :name="item.name" ></component>
                  </el-tab-pane>
            </el-tabs>
            <span slot="footer" class="dialog-footer">
                <el-button @click="kjColse">关 闭</el-button>
                <el-button type="primary" @click="saveKj">提 交</el-button>
                <el-button type="primary" @click="goTraining">前往训练</el-button>
            </span>
        </el-dialog>

        <!-- 编辑弹出框 -->
        <el-dialog title="查看" :visible.sync="editVisible" width="40%" :close-on-click-modal="false">
            <el-form ref="form" :model="form" :rules="addFormRules" label-width="100px" >
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="患者ID" prop="ptId" >
                            <el-input disabled v-model="form.ptId" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="姓名" prop="ptNm" >
                            <el-input disabled v-model="form.ptNm" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="性别" prop="ptSexText" >
                            <el-input disabled v-model="form.ptSexText" style="width: 100%"></el-input>
                        </el-form-item>
<!--                        <el-select v-model="form.ptSex" placeholder="请选择性别" style="width: 100%">-->
<!--                            <el-option key="00" label="男" value="00"></el-option>-->
<!--                            <el-option key="01" label="女" value="01"></el-option>-->
<!--                        </el-select>-->
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="手机号" prop="ptPhone">
                            <el-input disabled v-model="form.ptPhone" style="width: 100%;"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="20">
                        <el-form-item label="身高" prop="ptHeight">
                            <el-input disabled type="number" v-model="form.ptHeight" :min="1" placeholder="单位/cm" style="width: 100%;" @keyup.native="proving1"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="证件类型" prop="ptCerTp" >
                            <el-input disabled v-model="form.ptCerTpText" style="width: 100%"></el-input>
                        </el-form-item>

<!--                        <el-form-item label="" prop="ptCerTp">-->
<!--                            <el-select v-model="form.ptCerTp" style="width: 100%">-->
<!--                                <el-option key="00" label="身份证" value="00"></el-option>-->
<!--                                <el-option key="01" label="护照" value="01"></el-option>-->
<!--                            </el-select>-->
<!--                        </el-form-item>-->
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="证件号码" prop="ptCerNo">
                            <el-input  disabled v-model="form.ptCerNo" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="出生日期" prop="ptBirth">
                            <el-input  disabled v-model="form.ptBirth" style="width: 100%"></el-input>
                        </el-form-item>
<!--                        <el-form-item label="出生日期" prop="ptBirth" >-->
<!--                            <el-date-picker style="width: 100%;"-->
<!--                                            v-model="form.ptBirth"-->
<!--                                            type="date"-->
<!--                                            placeholder="选择日期"-->
<!--                                            value-format="yyyy-MM-dd"-->
<!--                                            :picker-options="ptBirthOptions">-->
<!--                           </el-date-picker>-->
<!--                        </el-form-item>-->
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="年龄" prop="ptAge">
                            <el-input  disabled type="number" ref="inputFormAge" v-model="form.ptAge" style="width: 100%;" :min="7" @keyup.native="proving1"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
<!--                <el-row>-->
<!--                    <el-col :span="10">-->
<!--                        <el-form-item label="减重值" prop="ptRedWg">-->
<!--                            <el-input v-model="form.ptRedWg" style="width: 100%;"></el-input>-->
<!--                        </el-form-item>-->
<!--                    </el-col>-->
<!--                    <el-col :span="10">-->
<!--                        <el-form-item label="重量" prop="ptWg" >-->
<!--                            <el-input readonly v-model="form.ptWg" ref="editinputTxt"  v-loading.fullscreen.lock="fullscreenLoadingEdit"  element-loading-text="称重中"  style="width: 100%;"></el-input>-->
<!--                        </el-form-item>-->
<!--                    </el-col>-->
<!--                    <el-col :span="2" style="padding-left: 4px">-->
<!--                        <el-button  @click="saveeditWg">称 重</el-button>-->
<!--                    </el-col>-->
<!--                </el-row>-->
                <el-row>
                    <el-col :span="20">
                        <el-form-item label="家庭住址" prop="ptAddres">
                            <el-input disabled   v-model="form.ptAddres" style="width: 100%;height: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editColse">关闭</el-button>
<!--                <el-button type="primary" @click="saveEdit">确 定</el-button>-->
            </span>
        </el-dialog>
        <!-- 新增弹出框 -->
        <el-dialog title="新增" :visible.sync="addPtVisible" width="40%" :close-on-click-modal="false">
            <el-form ref="addPtForm" :rules="addFormRules" :model="addPtForm" label-width="100px">
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="姓名" prop="ptNm" >
                            <el-input v-model="addPtForm.ptNm" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="性别" prop="ptSex">
                            <el-select v-model="addPtForm.ptSex" placeholder="请选择性别" style="width: 100%">
                                <el-option key="00" label="男" value="00"></el-option>
                                <el-option key="01" label="女" value="01"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="证件类型" prop="ptCerTp">
                            <el-select v-model="addPtForm.ptCerTp" style="width: 100%">
                                <el-option key="00" label="身份证" value="00"></el-option>
                                <el-option key="01" label="护照" value="01"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="证件号码" prop="ptCerNo">
                            <el-input  v-model="addPtForm.ptCerNo" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="出生日期" prop="ptBirth" >
                            <el-date-picker style="width: 100%;"
                                            v-model="addPtForm.ptBirth"
                                            type="date"
                                            placeholder="选择日期"
                                            value-format="yyyy-MM-dd"
                                            :picker-options="ptBirthOptions">
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="年龄" prop="ptAge">
                            <el-input type="number" v-model="addPtForm.ptAge" ref="inputAge" style="width: 70%;" :min="7" :max="120" @keyup.native="proving1"></el-input>&nbsp;(7~120)
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="10">
                        <el-form-item label="手机号" prop="ptPhone">
                            <el-input v-model="addPtForm.ptPhone" style="width: 100%;"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <el-form-item label="身高" prop="ptHeight">
                            <el-input type="number" v-model="addPtForm.ptHeight" :min="1" placeholder="单位/cm" style="width: 100%;" @keyup.native="proving1"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
<!--                <el-row>-->
<!--                    <el-col :span="10">-->
<!--                        <el-form-item label="减重值" prop="ptRedWg">-->
<!--                            <el-input v-model="addPtForm.ptRedWg" style="width: 100%;"></el-input>-->
<!--                        </el-form-item>-->
<!--                    </el-col>-->
<!--                    <el-col :span="10">-->
<!--                        <el-form-item label="重量" prop="ptWg" >-->
<!--                            <el-input readonly v-model="addPtForm.ptWg" ref="inputTxt" style="width: 100%;"></el-input>-->
<!--                        </el-form-item>-->
<!--                    </el-col>-->
<!--                    <el-col :span="2" style="padding-left: 4px">-->
<!--                        <el-button  @click="saveWg" v-loading.fullscreen.lock="fullscreenLoading"  element-loading-text="称重中">称 重</el-button>-->
<!--                    </el-col>-->
<!--                </el-row>-->
                <el-row>
                    <el-col :span="20">
                        <el-form-item label="家庭住址" prop="ptAddres">
                            <el-input   type="textarea"  v-model="addPtForm.ptAddres" style="width: 100%;"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click='closeAdd'>取 消</el-button>
                <el-button type="primary" @click="saveAdd">确 定</el-button>
            </span>
        </el-dialog>
        <!--评估弹出框-->
        <el-dialog title="评估信息" :visible.sync="assessVisible" width="50%" :close-on-click-modal="false">
            <div style="margin-bottom: 10px;">
                <el-form ref="kjForm" :rules="kjFormRules" :model="kjForm" label-width="70px">
                    <el-row style="margin-top: 10px">
                        <el-col :span="10" style="margin-left: 15px">
                            <span style="font-size: 20px;margin-bottom: 10px">患者ID： {{assessptId}}</span>
                        </el-col>
                        <el-col :span="4">
                            <span style="font-size: 20px;margin-bottom: 10px">姓名：{{assessptNm}}</span>
                        </el-col>
                        <el-col :span="4">
                            <span style="font-size: 20px;margin-bottom: 10px">性别： {{assessptSexText}}</span>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
            <el-tabs v-model="assesstableTabsValue" type="card">
                <el-tab-pane v-if="assesstableTabs && assesstableTabs.length >=0"
                             v-for="(item, index) in assesstableTabs"
                             :key="item.name"
                             :label="item.title"
                             :name="item.name">
                    <component :is="item.content"  v-on:assessformData="handleassessFormData" :name="item.name" ></component>
                </el-tab-pane>
            </el-tabs>
            <span slot="footer" class="dialog-footer">
                <el-button @click="assessColse">关 闭</el-button>
                <el-button type="primary" @click="saveAssess">提 交</el-button>
            </span>
        </el-dialog>
        <!-- 预约弹出框 -->
        <el-dialog title="预约信息" :visible.sync="appointVisible" width="20%" :close-on-click-modal="false">
            <el-form ref="appointForm" :model="appointForm" :rules="appointFormRules" label-width="100px" >
                <el-form-item hidden label="患者ID" prop="ptId" >
                    <el-input  v-model="appointForm.ptId" style="width: 100%"></el-input>
                </el-form-item>
                <el-form-item label="处方" prop="appointPreId">
                    <el-select v-model="appointForm.appointPreId" placeholder="请选择预约的处方" style="width: 80%">
                        <el-option v-for="aint in appoints" :label="aint.preId+'('+aint.preIstTm+')'" :key="aint.preId" :value="aint.preId"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="预约日期" prop="appointStartTm" >
                    <el-date-picker style="width: 80%;"
                                    v-model="appointForm.appointStartTm"
                                    type="date"
                                    placeholder="选择日期"
                                    value-format="yyyy-MM-dd"
                                    :picker-options="pickerOptions">
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="closeAppoint">取 消</el-button>
                <el-button type="primary" @click="saveAppoint">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 实时位置弹出框 -->
        <el-dialog ref="scharDialog" title="实时训练信息" :visible.sync="trainVisible" width="60%" :close-on-click-modal="false">
            <el-row style="margin-top: 10px">
                <el-col :span="8" style="margin-left: 15px">
                    <span style="font-size: 18px;margin-bottom: 10px">患者ID： {{this.condition.ptId}}</span>
                </el-col>
                <el-col :span="4">
                    <span style="font-size: 18px;margin-bottom: 10px">姓名：{{this.condition.ptNm}}</span>
                </el-col>
                <el-col :span="4">
                    <span style="font-size: 18px;margin-bottom: 10px">主治医生： {{this.condition.ptDoctor}}</span>
                </el-col>
                <el-col :span="4">
                    <span style="font-size: 18px;margin-bottom: 10px">剩余训练次数： {{this.condition.preTimes-this.condition.preOldTimes}}</span>
                </el-col>
            </el-row>
            <el-button style="margin-top: 12px" type="primary" @click="startTrain" :disabled="isStartButton">开始</el-button>
            <el-button type="success" @click="stopTrain" :disabled="isStopButton">暂停</el-button>
            <el-button type="success" plain @click="nowTrain" :disabled="isNowButton">继续</el-button>
            <el-button type="warning" plain @click="lastTrain" :disabled="isLastButton">下一个</el-button>
            <el-button type="info" plain @click="endTrain" :disabled="isEndButton">结束</el-button>
            <el-row>
                <el-col :span="10" style="margin-top: 20px">
                    <el-card shadow="hover" style="height:580px;overflow: scroll;overflow-x: hidden;border-color: #bcc7f0">
                        <el-row>
                            <el-col :span="10">
                                总进度
                            </el-col>
                            <el-col :span="10">
                                总时间:{{total+'/s'}}
                            </el-col>
                        </el-row>
                        <el-progress v-if="total===0" style="margin-top: 10px" :text-inside="true" :stroke-width="18" :format="format" :percentage="0"></el-progress>
                        <el-progress v-if="total!==0" style="margin-top: 10px" :text-inside="true" :stroke-width="18" :format="format" :percentage="current/total*100"></el-progress>
                        <div v-for="(v,i) in preList">
                            <span style="color: #5ec211;font-size: 16px">处方{{i+1}}</span>
                            <el-card  shadow="always"  height="60" style="border-color: #bcc7f0;margin-top: 5px">
                                <!--卡片中的内容-->
                                <el-form ref="preform" :model="preform" label-width="100px">
                                    <el-row>
                                        <el-col :span="13">
                                            <el-form-item label="运动类型" prop="preActionType" >
                                                <el-input readonly v-model="preList[i].preActionTypeText" style="width: 100%">
                                                </el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="13">
                                            <el-form-item label="是否电刺激" prop="preActionElectricalStatus" >
                                                <el-input readonly v-model="preList[i].preActionElectricalStatusText" style="width: 100%"></el-input>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="13" v-if="preList[i].preActionElectricalStatus=='01'">
                                            <el-form-item  label="刺激类型" prop="preActionElectrical" >
                                                <el-input readonly v-model="preList[i].preActionElectricalText" style="width: 100%"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row v-if="preList[i].preActionElectricalStatus=='01'">
                                        <el-col :span="18" v-if="preList[i].isFinished ==undefined">
                                            <el-form-item    label="幅度值" prop="preActionAmplitude" >
                                                <el-button disabled type="success" plain  @click="downPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">-</el-button>
                                                <el-input  readonly v-model="preList[i].preActionAmplitude" style="margin-left: 5px;width: 30%"></el-input>
                                                <el-button disabled type="success" plain style="margin-left: 5px" @click="upPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">+</el-button>
                                            </el-form-item>
                                        </el-col>
                                        <!--幅度值分为三种 1.已结束运动的，+ -不可点击 2.正在运行的 + - 可以点击  3.未开始的 + - 不可点击  幅度值 0~99-->
                                        <!--1.已结束-->
                                        <el-col :span="18" v-if="preList[i].isFinished!==undefined && preList[i].isFinished==true">
                                            <el-form-item    label="幅度值" prop="preActionAmplitude" >
                                                <el-button disabled type="success" plain  @click="downPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">-</el-button>
                                                <el-input  readonly v-model="preList[i].preActionAmplitude" style="margin-left: 5px;width: 30%" ref="PreAmp"></el-input>
                                                <el-button disabled type="success" plain style="margin-left: 5px" @click="upPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">+</el-button>
                                            </el-form-item>
                                        </el-col>
                                        <!--2.正在运行-->
                                        <el-col :span="18" v-if="preList[i].isFinished==false && preList[i].current !==0 && preList[i].current<preList[i].total">
                                            <el-form-item    label="幅度值" prop="preActionAmplitude" >
                                                <el-button  type="success" plain  @click="downPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">-</el-button>
                                                <el-input  readonly v-model="preList[i].preActionAmplitude" style="margin-left: 5px;width: 30%"  ref="PreAmp"></el-input>
                                                <el-button type="success" plain style="margin-left: 5px" @click="upPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">+</el-button>
                                            </el-form-item>
                                        </el-col>
                                        <!--3.还未进行-->
                                        <el-col :span="18" v-if="preList[i].isFinished!==undefined && preList[i].isFinished==false && preList[i].current==0">
                                            <el-form-item    label="幅度值" prop="preActionAmplitude" >
                                                <el-button disabled type="success" plain  @click="downPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">-</el-button>
                                                <el-input  readonly v-model="preList[i].preActionAmplitude" style="margin-left: 5px;width: 30%"  ref="PreAmp"></el-input>
                                                <el-button disabled type="success" plain style="margin-left: 5px" @click="upPreAmp(preList[i].preId,preList[i].preActionId,preList[i].preActionAmplitude,i)">+</el-button>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row v-if="preList[i].preActionType=='01'">
                                        <el-col :span="12">
                                            <el-form-item  label="左脚速度" prop="preActionLeftSpeed" >
                                                <el-input readonly type="number" v-model="preList[i].preActionLeftSpeed"  :min="1" style="width: 100%"></el-input>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item   label="右脚速度" prop="preActionRightSpeed" >
                                                <el-input readonly type="number" v-model="preList[i].preActionRightSpeed" :min="1" style="width: 100%"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="17">
                                            <el-form-item  label="痉挛值" prop="preActionSpasm" >
                                                <el-input readonly type="number" v-model="preList[i].preActionSpasm" :min="1" :max="3" style="width: 60%" ></el-input> 级(1,2,3)
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="17">
                                            <el-form-item  label="运动时间" prop="preActionTime" >
                                                <el-input readonly type="number" v-model="preList[i].preActionTime/60" :min="1" style="width: 60%"></el-input> 分钟
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                                <!--已结束 完成-->
                                <el-progress v-if="preList[i].isFinished==true" :percentage="100" :show-text="showText"></el-progress>
                                <!--正在运行-->
                                <el-progress v-if="preList[i].isFinished==false && preList[i].current !==0 && preList[i].current<preList[i].total" :show-text="showText" :percentage="preList[i].current/preList[i].total*100" >
                                </el-progress>
                                <!--还未进行 -->
                                <el-progress v-if="preList[i].isFinished==false && preList[i].current==0" :show-text="showText" :percentage="0" ></el-progress>
                                <!--初始化-->
                                <el-progress v-if="preList[i].isFinished==undefined && preList[i].current==undefined && preList[i].total==undefined " :show-text="showText" :percentage="0" ></el-progress>
                            </el-card>
                        </div>
                    </el-card>
                </el-col>
                <el-col :span="10" style="margin-left: 40px">
                    <el-row>
                        <el-col :span="8">
<!--                            <schart class="schart" canvasId="line"  :options="leftOptions"></schart>-->
                            <div id="myleftChart" style="width:550px;height: 300px" v-if="showDiv"></div>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
<!--                            <schart  class="schart" canvasId="line2"   :options="rigthOptions"></schart>-->
                            <div id="myrigthChart" style="width:550px;height: 300px" v-if="showDiv"></div>
                        </el-col>
                    </el-row>
                </el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button @click="closeTrain">关 闭</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import model from '../patient/model';
    import assessOneModel from '../patient/assessOneModel';
    import assessTwoModel from '../patient/assessTwoModel';
    import assessThreeModel from '../patient/assessThreeModel';
    import assessForeModel from '../patient/assessForeModel';
    import { patientData,getWg,isNotExists,doAdd,doUpdate,doDelete,getDoctors,saveReplaceDoct,goOutHospital,saveCf,saveAssess,selectPresptByPtId,saveAppoint } from '../../../../api/stand/patient/patient';
    import { getcrtBys } from '../../../../api/system/user/user';
    import {
        sendEleTrainReduce,
        startTraining,
        play,
        stopTrain,
        resume,
        goNextAction,
        stop,
        sendEleTrainAdd,
        sendReset
    } from '../../../../api/stand/train/train';
    import Schart from 'vue-schart';
    import {selectBypreId} from "../../../../api/stand/prescription/prescription";
    export default {
        name: 'patient',
        data() {
            return {
                query: {//检索条件
                    ptNm: '',
                    hospitalId:'',
                    userAcct:localStorage.getItem('ms_userAcct'),
                    pageIndex: 1,
                    pageSize: 10
                },
                condition:{
                    ptId:'',
                    ptNm:'',
                    ptDoctor:'',
                    preTimes:'',
                    preOldTimes:''
                },
                tableData: [],
                multipleSelection: [],
                delList: [],
                editVisible: false,
                replaceDoctorVisible:false,
                prescriptionVisible:false,
                pageTotal: 0,
                userAccts:[],
                roleIds:localStorage.getItem('ms_roleIds'),
                replaceform:{
                    userAcct:'',
                    ptId:'',
                    ptNm:''
                },
                form: {
                    ptId:'',
                    ptNm:'',
                    ptSex:'',
                    ptCerTp:'',
                    ptCerNo:'',
                    ptBirth:'',
                    ptAge:'',
                    ptPhone:'',
                    ptDoctor:'',
                    ptRedWg:'',
                    ptWg:'',
                    ptAddres:'',
                    ptHeight:'',
                },
                addPtVisible: false,
                fullscreenLoading:false,
                fullscreenLoadingEdit:false,
                assessVisible:false,
                addPtForm:{
                    ptNm:'',
                    ptSex:'',
                    ptCerTp:'',
                    ptCerNo:'',
                    ptBirth:'',
                    ptAge:'',
                    ptPhone:'',
                    ptDoctor:'',
                    ptRedWg:'',
                    ptWg:'',
                    ptAddres:'',
                    ptHeight:'',
                },
                kjForm:{},
                namess:[],
                idx: -1,
                id: -1,
                addFormRules: {
                    ptNm: [
                        { required: true, message: '请输入患者姓名', trigger: 'blur' },
                    ],
                    ptBirth: [
                        { required: true, message: '请输入患者出生日期', trigger: 'blur' },
                    ],
                    // ptAge:[
                    //     { min: 1, max: 3, message: '长度在 1 到 3 个字符', trigger: 'blur' }
                    // ],
                    ptSex: [
                        { required: true, message: '请选择患者性别', trigger: 'blur' }
                    ],
                    ptPhone:[
                        { required: true, message: '请输入手机号', trigger: 'blur' }
                    ],
                    ptCerTp: [
                        { required: true, message: '请选择证件类型', trigger: 'blur' }
                    ],
                    ptCerNo: [
                        { required: true, message: '请输入证件号码', trigger: 'blur' },
                        // {pattern: /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/, message: '证件号码格式有误！', trigger: 'blur'}
                    ],
                    ptDoctor: [
                        { required: true, message: '请输入主治医生姓名', trigger: 'blur' }
                    ],
                },
                appointFormRules: {
                    appointPreId: [
                        { required: true, message: '请选择处方', trigger: 'blur' },
                    ],
                    appointStartTm: [
                        { required: true, message: '请选择预约日期',trigger: 'blur' },
                    ],
                },
                kjFormRules:{
                    preTimes: [
                        { required: true, message: '请输入训练次数', trigger: 'blur' },
                    ],
                },
                editableTabsValue: '1',
                editableTabs: [],
                tabIndex: 1,
                assesstableTabsValue: '1',
                assesstableTabs: [],
                assesstabIndex: 1,
                assessptId:'',
                assessptNm:'',
                assessptSexText:'',
                assessModels:[],
                assessnamess:[],
                crtBys:[],
                modelForms:[],
                isRouterAlive:true,
                appointVisible:false,
                appointForm:{},
                appoints:[],
                trainVisible:false,
                trainData:{
                    preId:"",
                    ptId:''
                },
                isStartButton:false,
                isStopButton:true,
                isNowButton:true,
                isLastButton:true,
                isEndButton:true,
                taskId:'',
                timer:'',
                leftOptions: {},
                leftLabels:[],
                leftData:[],
                rigthOptions: {},
                rigthLabels:[],
                rigthData:[],
                pickerOptions: {
                    disabledDate(time) {
                        return time.getTime() < Date.now() - 8.64e7;
                    }
                },
                ptBirthOptions:{
                    disabledDate(time) {
                        return time.getTime() > Date.now() - 8.64e6;
                    }
                },
                preList:[],
                form:{},
                preform:{},
                total:1,
                current:0,
                showText:false,
                showDiv:false,
            };
        },

        created() {
            this.getData();
        },
        watch:{
            'addPtForm.ptBirth': {
                handler:function () {
                    if (this.addPtForm.ptBirth!==undefined && this.addPtForm.ptBirth !==null && this.addPtForm.ptBirth !==""){
                        //输入出生日期，自动填充年龄
                        console.log("addPtForm.ptBirth",this.addPtForm.ptBirth);
                        const year=new Date().getFullYear();
                        const ptBirthYear=this.addPtForm.ptBirth.slice(0,4);
                        console.log("现在年份：",year);
                        console.log("生日年份：",ptBirthYear);
                        if (year-ptBirthYear<7){
                            this.$refs.inputAge.value=7;
                            this.addPtForm.ptAge=7;
                            return;
                        }
                        if (year-ptBirthYear>120){
                            this.$refs.inputAge.value=120;
                            this.addPtForm.ptAge=120
                            return;
                        }
                        this.$refs.inputAge.value = year-ptBirthYear;    // 给有 ref 属性的 input 赋值
                        this.addPtForm.ptAge=year-ptBirthYear;
                    }

                }
            },
            'form.ptBirth': {
                handler:function () {
                    if (this.form.ptBirth!==undefined && this.form.ptBirth !==null && this.form.ptBirth !==""){
                        //输入出生日期，自动填充年龄
                        console.log("form.ptBirth",this.form.ptBirth);
                        const year=new Date().getFullYear();
                        const ptBirthYear=this.form.ptBirth.slice(0,4);
                        console.log("现在年份：",year);
                        console.log("生日年份：",ptBirthYear);
                        if (year-ptBirthYear<7){
                            this.$refs.inputFormAge.value=7;
                            this.form.ptAge=7;
                            return;
                        }
                        if (year-ptBirthYear>120){
                            this.$refs.inputFormAge.value=120;
                            this.form.ptAge=120
                            return;
                        }
                        this.$refs.inputFormAge.value = year-ptBirthYear;    // 给有 ref 属性的 input 赋值
                        this.form.ptAge=year-ptBirthYear;
                    }

                }
            },
        },
        components:{
            model,
            assessOneModel,
            assessTwoModel,
            assessThreeModel,
            assessForeModel,
            Schart
        },
        methods: {
            // 获取 easy-mock 的模拟数据
            getData() {
                console.log("进入患者信息----",this.query);
                patientData(this.query).then(res => {
                    this.tableData = res.data;
                    this.pageTotal = res.total;
                });
            },
            // 触发搜索按钮
            handleSearch() {
                this.$set(this.query, 'pageIndex', 1);
                this.getData();
            },
            // 触发重置按钮
            handleReset() {
                this.query.ptNm = "";
                this.query.hospitalId = "";
                this.getData();
            },
            // 新增操作
            handleAdd() {
                this.addPtVisible = true;
            },
            //称重(新增时)
            saveWg(){
                this.fullscreenLoading = true;
                setTimeout(() => {
                    getWg().then(res => {
                        if (res.data!==null && res.data!==''){
                            this.fullscreenLoading = false;
                            this.$refs.inputTxt.value = res.data;    // 给有 ref 属性的 input 赋值
                            this.addPtForm.ptWg=res.data;
                        }
                    });
                }, 1000);

            },
            //称重(编辑时)
            saveeditWg(){
                this.fullscreenLoadingEdit = true;
                setTimeout(() => {
                    getWg().then(res => {
                        if (res.data!==null && res.data!==''){
                            this.fullscreenLoadingEdit = false;
                            this.$refs.editinputTxt.value = res.data;    // 给有 ref 属性的 input 赋值
                            this.form.ptWg=res.data;
                        }
                    });
                }, 1000);
            },
            /*新增用户*/
            saveAdd(){
                // validate 函数 表单验证
                this.$refs['addPtForm'].validate((valid) => {
                    if (valid) {
                        console.log("this.addPtForm.ptHeight:",this.addPtForm.ptHeight);
                        if (this.addPtForm.ptAge<7 || this.addPtForm.ptAge>120){
                            this.$message.error('年龄应该在7-120范围');
                        }else{
                            let isExistQuery={//判断证件类型证件号是否存在条件
                                ptCerTp:this.addPtForm.ptCerTp,
                                ptCerNo:this.addPtForm.ptCerNo
                            };
                            //判断证件类型和证件号是否已经存在
                            isNotExists(isExistQuery).then(res => {
                                if (res.data){//患者不存在

                                    this.addPtForm.ptDoctor= localStorage.getItem('ms_userAcct');
                                    //提交 到后台
                                    doAdd(this.addPtForm).then(res => {
                                        if (res.data==1){
                                            this.addPtVisible=false;
                                            this.addPtForm={};
                                            this.getData();
                                            this.$message.success('保存成功');
                                        }else{
                                            this.$message.error('保存失败');
                                        }
                                    });
                                }else{
                                    this.$message.error('该患者已存在');
                                }
                            });
                        }
                    }
                });
            },
            closeAdd(){//关闭新增弹出框
                    this.$confirm('确认关闭？', '提示', {
                        type: 'warning'
                    })
                        .then(() => {
                            this.addPtVisible=false;
                            this.addPtForm={};
                            this.getData();
                        })
                        .catch(() => {
                            this.$message({
                                message:'已取消操作'
                            });
                        });
            },
            // 删除操作
            handleDelete(index, row) {
                // 二次确认删除
                this.$confirm('确定要删除吗？', '提示', {
                    type: 'warning'
                })
                    .then(() => {
                        //后台进行删除操作
                        doDelete({"ptId":row.ptId}).then(res => {
                            console.log("doDelete--",res);
                            if (res.data==1){
                                this.$message.success('删除成功');
                                this.getData();
                            }else {
                                if (res.status=="000001"){//查询的信息不存在
                                    this.$message.error('该患者不存在');
                                }if (res.status=="000002"){
                                    this.$message.error('该患者已存在处方，无法删除');
                                }else{
                                    this.$message.error('删除失败');
                                }
                                this.getData();
                            }
                        });
                    })
                    .catch(() => {
                        this.$message({
                            message:'已取消删除'
                        });
                        this.getData();
                    });
            },
            // 多选操作
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            // 编辑操作
            handleEdit(index, row) {
                this.form = {};
                this.idx = index;
                this.form = row;
                this.editVisible = true;
            },
            // 保存编辑
            saveEdit() {
                if (this.form.ptAge<7 || this.form.ptAge>120){
                    this.$message.error('年龄应该在7-120范围');
                }else{
                    if (typeof this.form.ptBirth !=="string"){
                        let editptBirth=this.form.ptBirth.getFullYear() + '-' + (this.form.ptBirth.getMonth() + 1) + '-' + this.form.ptBirth.getDate();
                        this.form.ptBirth=editptBirth;
                    }
                    //修改后的数据发送到后台
                    doUpdate(this.form).then(res => {
                        if (res.data == 1) {
                            this.editVisible = false;
                            this.form = {};
                            this.getData();
                            this.$message.success('编辑成功');
                        } else {
                            this.$message.error('编辑失败');
                        }
                    });
                }
            },
            editColse(){//关闭编辑弹出框
                this.editVisible=false;
            },
            //更换医生
            replaceDoctor(index, row){
                this.replaceDoctorVisible=true;
                this.replaceform.ptId=row.ptId;
                this.replaceform.ptNm=row.ptNm;
                //调用后台查询医生列表
                getDoctors().then(res => {
                    this.userAccts=res.data;
                });
            },
            replaceDoctColse(){
                this.replaceDoctorVisible=false;
                this.replaceform={};
                this.getData();
            },
            //保存更换医生
            saveReplaceDoct(){
                //调用后台
                saveReplaceDoct(this.replaceform).then(res => {
                        if (res.data == 1) {
                        this.replaceDoctorVisible = false;
                        this.replaceform = {};
                        this.getData();
                        this.$message.success('更换医师成功');
                    } else {
                        this.$message.error('更换失败');
                    }
                })
            },
            //患者转出
            goOut(index, row){
                this.$confirm('确认转出？', '提示', {
                    type: 'warning'
                })
                    .then(() => {
                        let query={
                            ptId:row.ptId,
                        }
                        //调用后台查询医生列表
                        goOutHospital(query).then(res => {
                            if (res.data==1){
                                this.$message.success('转出成功');
                                this.getData();
                            } else {
                                this.$message.error('转出失败');
                            }
                        });
                    })
                    .catch(() => {
                        this.$message({
                            message:'已取消操作'
                        });
                    });
            },
            //患者预约
            goAppoint(index, row){
                this.appointForm={};
                //查询该患者开过的处方 （次数已用完排除）
                  selectPresptByPtId({ptId:row.ptId,}).then(res =>{
                    if (res.success==true){
                        this.appointForm.appointPtId=row.ptId;
                        this.appoints=res.data;
                        this.appointVisible=true;
                    }
                });
            },
            //保存预约信息
            saveAppoint(){
                this.$refs['appointForm'].validate((valid) => {
                        if (valid) {
                        this.appointForm.appointCrtBy=localStorage.getItem('ms_userAcct');
                        console.log("this.appointForm",this.appointForm);
                        saveAppoint(this.appointForm).then(res => {
                            if (res.data == 1) {
                                this.appointVisible = false;
                                this.$message.success('预约成功');
                                this.getData();
                            } else {
                                this.$message.error('预约失败');
                            }
                        });
                    }
                });
            },
            //关闭预约信息
            closeAppoint(){
                this.appointVisible=false;
            },
            //开具处方
            goPrescription(index, row){
                //获取所有治疗师
                getcrtBys().then(res =>{
                    this.kjForm = {};
                    this.namess=[];
                    this.editableTabsValue='1';
                    this.editableTabs=[
                        {
                            title: '训练类型选择',
                            name: '1',
                            content:'model'
                        }
                    ];
                    this.tabIndex=1;
                    this.crtBys = res.data;
                    this.condition.ptId=row.ptId;
                    this.condition.ptNm=row.ptNm;
                    this.condition.ptDoctor=row.ptDoctor;
                    this.prescriptionVisible=true;
                });
            },
            addTab(targetName) {
                //每个tab的内容
                let newTabName = ++this.tabIndex + '';
                this.editableTabs.push({
                    title: '训练类型选择',
                    name: newTabName,
                    content:'model'
                });
                this.editableTabsValue = newTabName;
            },
            removeTab(targetName) {
                let tabs = this.editableTabs;
                let activeName = this.editableTabsValue;
                if (activeName === targetName) {
                    tabs.forEach((tab, index) => {
                        if (tab.name === targetName) {
                            let nextTab = tabs[index + 1] || tabs[index - 1];
                            if (nextTab) {
                                activeName = nextTab.name;
                            }
                        }
                    });
                }
                this.editableTabsValue = activeName;
                this.editableTabs = tabs.filter(tab => tab.name !== targetName);
                const  result=[];
                this.modelForms.forEach((item, index) => {
                    if (item.name!==targetName){
                        result.push(item);
                    }
                });
                this.modelForms=result;
            },
            //保存开具处方
            saveKj(){
                // validate 函数 表单验证
                this.$refs['kjForm'].validate((valid) => {
                    if (valid) {
                        if (this.editableTabs.length==0){
                            this.$message.error('请至少保存一个处方记录');
                            return;
                        }
                        //判断治疗师是否已经选择
                        if (this.kjForm.preCrtBy==undefined || this.kjForm.preCrtBy==null || this.kjForm.preCrtBy==""){
                            this.$message.error('请选择治疗师');
                            return;
                        }
                        if (this.kjForm.preTimes==undefined || this.kjForm.preTimes==null || this.kjForm.preTimes=="" || this.kjForm.preTimes=="0"){
                            this.$message.error('请正确输入训练次数');
                            return;
                        }
                        if (this.modelForms.length!==0){
                            //判断第几个页签是未保存的
                            let returnStr="";
                            for (let i=0;i<this.editableTabs.length;i++){
                                //查找是否有保存的
                                if (this.modelForms.length!==0) {
                                    for (let j = 0; j < this.modelForms.length; j++) {
                                        if (this.editableTabs[i].name == this.modelForms[j].name) {
                                            break;
                                        }
                                        if (j == this.modelForms.length - 1 && this.editableTabs[i].name !== this.modelForms[j].name) {
                                            returnStr = returnStr + (i + 1) + ',';
                                        }
                                    }
                                }else{
                                    returnStr = returnStr + (i + 1) + ',';
                                }
                            }
                            if (returnStr!==""){
                                returnStr=returnStr.substring(0,returnStr.length-1);
                                this.$message.error("标签页："+returnStr+"未保存，请保存");
                                return;
                            }
                            console.log("json:",this.modelForms);
                            saveCf({"json":JSON.stringify({"standPrescriptionActionPOJOS":this.modelForms,"preTherape":this.kjForm.preCrtBy,"preTimes":this.kjForm.preTimes,"ptId":this.condition.ptId,"preCrtBy":localStorage.getItem('ms_userAcct'),})}).then(res =>{
                                if (res.success == true) {
                                    this.editableTabs=[];
                                    this.modelForms=[];
                                    this.kjForm={};
                                    this.prescriptionVisible = false;
                                    this.$message.success('开具处方成功');
                                    this.getData();
                                } else {
                                    this.$message.error('开具处方失败');
                                }
                            });
                        }else{
                            this.$message.error('未保存相关处方，请保存');
                        }
                    }
                });
            },
            //开始根据处方进行训练
            async goTraining(){
                // validate 函数 表单验证
                await this.$refs['kjForm'].validate((valid) => {
                    if (valid) {
                        if (this.modelForms.length!==0) {
                            if (this.editableTabs.length==0){
                                this.$message.error('请至少保存一个处方记录');
                                return;
                            }
                            if (this.kjForm.preTimes==undefined || this.kjForm.preTimes==null || this.kjForm.preTimes=="" || this.kjForm.preTimes=="0"){
                                this.$message.error('请正确输入训练次数');
                                return;
                            }
                            //判断第几个页签是未保存的
                            let returnStr="";
                            for (let i=0;i<this.editableTabs.length;i++){
                                if (this.modelForms.length!==0){
                                    //查找是否有保存的
                                    for (let j=0;j<this.modelForms.length;j++){
                                        if (this.editableTabs[i].name==this.modelForms[j].name){
                                            break;
                                        }
                                        if (j==this.modelForms.length-1 && this.editableTabs[i].name !==this.modelForms[j].name){
                                            returnStr=returnStr+(i+1)+',';
                                        }
                                    }
                                }else{
                                    returnStr=returnStr+(i+1)+',';
                                }
                            }
                            if (returnStr!==""){
                                returnStr=returnStr.substring(0,returnStr.length-1);
                                console.log("returnStr----",returnStr);
                                this.$message.error("标签页："+returnStr+"未保存，请保存");
                                return;
                            }
                            console.log("standPrescriptionActionPOJOS:",this.modelForms);
                             saveCf({
                                "json": JSON.stringify({
                                    "standPrescriptionActionPOJOS": this.modelForms,
                                    "preTherape": this.kjForm.preCrtBy==undefined || this.kjForm.preCrtBy==null || this.kjForm.preCrtBy==""?'':this.kjForm.preCrtBy,//治疗师
                                    "preCrtBy":localStorage.getItem('ms_userAcct'),//处方创建者
                                    "preTimes": this.kjForm.preTimes,
                                    "ptId": this.condition.ptId
                                })
                            }).then(saveCfres => {
                                if (saveCfres.success == true) {
                                    console.log("result", {
                                        "standPrescriptionActionPOJOS": this.modelForms,
                                        "preTherape": this.kjForm.preCrtBy==undefined || this.kjForm.preCrtBy==null || this.kjForm.preCrtBy==""?'':this.kjForm.preCrtBy,//治疗师
                                        "preCrtBy":localStorage.getItem('ms_userAcct'),//处方创建者
                                        "preTimes": this.kjForm.preTimes,
                                        "ptId": this.condition.ptId
                                    });
                                    const loading = this.$loading({
                                        lock: true,
                                        text: '复位中',
                                        spinner: 'el-icon-loading',
                                        background: 'rgba(0, 0, 0, 0.7)'
                                    });
                                    sendReset().then(res => {
                                        loading.close();
                                        if (res.success==true){
                                            //根据处方id查询处方记录
                                            selectBypreId({preId: saveCfres.data}).then(res => {
                                                if (res.success==true){
                                                    this.showDiv=false;
                                                    this.preList=res.data.standPrescriptionActionPOJOS;
                                                    this.trainData.ptId=this.condition.ptId;
                                                    this.trainData.preId=res.data.preId;
                                                    this.editableTabs = [];
                                                    this.modelForms = [];
                                                    this.kjForm = {};
                                                    this.prescriptionVisible = false;
                                                    this.isStartButton=false;
                                                    this.isStopButton=true;
                                                    this.isNowButton=true;
                                                    this.isLastButton=true;
                                                    this.isEndButton=true;
                                                    //复位成功 弹出实时左右脚弹出框
                                                    this.taskId="";
                                                    this.timer="";
                                                    this.leftLabels=[];
                                                    this.leftData=[];
                                                    this.leftOptions={};
                                                    this.rigthLabels=[];
                                                    this.rigthData=[];
                                                    this.rigthOptions={};
                                                    this.condition.preTimes=res.data.preTimes;
                                                    this.condition.preOldTimes=res.data.preOldTimes;
                                                    this.current=0;
                                                    this.total=0;
                                                    this.trainVisible = true;
                                                }else{
                                                    this.$message.error('处方查询失败');
                                                }
                                            });
                                        }else{
                                            this.$message.error('复位失败');
                                            loading.close();
                                        }
                                    });

                                } else {
                                    this.$message.error('处方保存失败');
                                }
                            });
                        }else{
                            this.$message.error('未查询到可训练的处方');
                        }
                    }
                });
            },
            //获取后台数据
            getNewMessage: function() {
                play({taskId:this.taskId}).then(res => {
                    console.log("res",res);
                    if (res.success==true) {
                        if (res.data.isFinished == true) {
                            window.clearInterval(this.timer);
                            this.trainVisible = false;
                            this.$message.success('结束训练成功');
                        } else {
                            for (let i = 0; i <this.preList.length; i++) {
                                for (let j = 0; j <res.data.actions.length; j++) {
                                    if (this.preList[i].preId==res.data.actions[j].standPrescriptionActionPOJO.preId && this.preList[i].preActionId==res.data.actions[j].standPrescriptionActionPOJO.preActionId){
                                        this.preList[i].isFinished=res.data.actions[j].isFinished;
                                        this.preList[i].current=res.data.actions[j].current;
                                        this.preList[i].total=res.data.actions[j].total;
                                    }
                                };
                            };
                            this.total=res.data.total;
                            this.current=res.data.current;
                            // console.log("值",((res.data.current/res.data.total)+'').substring(0,((res.data.current/res.data.total)+'').indexOf('.')+6));
                            // console.log("-----数值",Number(0.066*100).toFixed(2));
                            let nowTime = "";
                            if (res.data.standPreApmPOJO !== null && res.data.standPreApmPOJO !== undefined && res.data.standPreApmPOJO.paIstTm !== undefined && res.data.standPreApmPOJO.paIstTm !== null && res.data.standPreApmPOJO.paIstTm !== "") {
                                //后台传过来的时间，进行格式化成时分秒
                                nowTime = res.data.standPreApmPOJO.paIstTm.slice(14,19);
                                console.log("nowTime", nowTime);
                                //左 右
                                if (this.leftLabels.length >= 10) {
                                    this.leftLabels = this.leftLabels.slice(1, this.leftLabels.length);
                                }
                                ;
                                this.leftLabels.push(nowTime);
                                if (this.rigthLabels.length >= 10) {
                                    this.rigthLabels = this.rigthLabels.slice(1, this.rigthLabels.length);
                                }
                                ;
                                this.rigthLabels.push(nowTime);
                                if (this.leftData.length >= 10) {
                                    this.leftData = this.leftData.slice(1, this.leftData.length);
                                }
                                ;
                                this.leftData.push(res.data.standPreApmPOJO.paLeftAcPos);
                                if (this.rigthData.length >= 10) {
                                    this.rigthData = this.rigthData.slice(1, this.rigthData.length);
                                }
                                ;
                                this.rigthData.push(res.data.standPreApmPOJO.paRightAcPos);
                                this.leftOptions = {
                                    title:{
                                        text:'左脚运动位置'
                                    },
                                    tooltip:{
                                        trigger:'axis',
                                    },
                                    xAxis:{
                                        // type:'category',
                                        data:this.leftLabels,
                                        name: '时间',
                                        splitLine: { // 去除网格区域
                                            show: false,
                                        }
                                    },
                                    yAxis:{
                                        type:'value',
                                        scale: true,
                                        min:0,
                                        max:100,
                                    },
                                    series:[{
                                        type:'bar',
                                        itemStyle:{
                                            color:"#3591FF"
                                        },
                                        data: this.leftData
                                    }]
                                };
                                this.rigthOptions = {
                                    title:{
                                        text:'右脚运动位置'
                                    },
                                    tooltip:{
                                        trigger:'axis',
                                    },
                                    xAxis:{
                                        // type:'category',
                                        data:this.rigthLabels,
                                        name: '时间',
                                        splitLine: { // 去除网格区域
                                            show: false,
                                        }
                                    },
                                    yAxis:{
                                        type:'value',
                                        scale: true,
                                        min:0,
                                        max:100,
                                    },

                                    series:[{
                                        type:'bar',
                                        itemStyle:{
                                            color:"#3591FF"
                                        },
                                        data: this.rigthData
                                    }]
                                };
                                    let myleftChart=this.$echarts.init(document.getElementById('myleftChart'));
                                    myleftChart.setOption(this.leftOptions);
                                    let myrigthChart=this.$echarts.init(document.getElementById('myrigthChart'));
                                    myrigthChart.setOption(this.rigthOptions);
                            }
                        }
                    }else{
                        this.$message.error('获取实时位置失败');
                    }
                });
            },
            //开始
            async startTrain(){
                //开始训练
                await  startTraining(this.trainData).then(res => {
                    //开始训练 返回taskId
                    if (res.success == true) {
                        this.$message.success('开始成功');
                        this.showDiv=true;
                        this.isStartButton=true;
                        this.isStopButton=false;
                        this.isLastButton=false;
                        this.isEndButton=false;
                        this.taskId=res.data;
                        //每一秒 调用后台获取位置信息
                        this.timer=window.setInterval(() => {
                            setTimeout(this.getNewMessage(), 0);
                        }, 1000);
                    }else {
                        this.$message.error(res);
                    }
                });
            },
            //暂停
            async stopTrain(){
                window.clearInterval(this.timer);
                this.isStopButton=true;
                this.isNowButton=false;
                await  stopTrain({taskId:this.taskId}).then(res => {
                    if (res.data==1){
                        this.$message.success('暂停成功');
                    }else{
                        this.$message.error('暂停失败');
                    }
                });
            },
            //继续
            async nowTrain(){
                this.isNowButton=true;
                this.isStopButton=false;
                await  resume({taskId:this.taskId}).then(res => {
                    if (res.data==1){
                        this.$message.success('继续成功');
                        window.clearInterval(this.timer);
                        this.timer=window.setInterval(() => {
                            setTimeout(this.getNewMessage(), 0);
                        }, 1000);
                    }else{
                        this.$message.error('继续失败');
                    }
                });
            },
            //下一个
            async lastTrain(){
                this.isStopButton=false;
                this.isNowButton=true;
                await  goNextAction({taskId:this.taskId}).then(res => {
                    if (res.data==1){
                        this.$message.success('下一个成功');
                        window.clearInterval(this.timer);
                        this.timer=window.setInterval(() => {
                            setTimeout(this.getNewMessage(), 0);
                        }, 1000);
                    }
                });
            },
            //结束
            async endTrain(){
                window.clearInterval(this.timer);
                console.log(" endTrain taskId",this.taskId);
                await  stop({taskId:this.taskId}).then(res => {
                    if (res.success==true){
                        this.trainVisible=false;
                        this.modelForms=[];
                        this.kjForm={};
                        this.taskId="";
                        this.timer="";
                        this.leftOptions={};
                        this.leftLabels=[];
                        this.leftData=[];
                        this.rigthOptions={};
                        this.rigthLabels=[];
                        this.rigthData=[];
                        this.$message.success('结束训练成功');
                    }else{
                        this.$message.error('结束失败');
                    }
                });


            },
            //关闭实时运动位置弹出框
             closeTrain(){
                this.$confirm('确认关闭？', '提示', {
                    type: 'warning'
                })
                    .then(() => {
                        if (this.taskId==''){
                            window.clearInterval(this.timer);
                            this.trainVisible=false;
                            return;
                        }
                            stop({taskId:this.taskId}).then(res => {
                                if (res.success == true) {
                                    window.clearInterval(this.timer);
                                    this.$message.success('结束训练成功');
                                    this.modelForms=[];
                                    this.kjForm={};
                                    this.leftOptions={};
                                    this.leftLabels=[];
                                    this.leftData=[];
                                    this.rigthOptions={};
                                    this.rigthLabels=[];
                                    this.rigthData=[];
                                    this.trainVisible=false;
                                }else{
                                    this.$message.error("训练结束失败");
                                }
                            });
                    })
                    .catch(() => {
                        this.$message({
                            message:'已取消操作'
                        });
                    });

            },
            //开具处方弹出框关闭
            kjColse(){
                this.$confirm('确认关闭？', '提示', {
                    type: 'warning'
                })
                    .then(() => {
                        this.kjForm = {};
                        this.modelForms=[];
                        this.namess=[];
                        this.editableTabs=[];
                        this.getData();
                        this.prescriptionVisible=false;
                    })
                    .catch(() => {
                        this.$message({
                            message:'已取消操作'
                        });
                    });
            },
            // 处理子组件传递数据(开具处方)
            handleFormData:function (somedata) {
                somedata.preActionTime=somedata.preActionTime *60;
                let modelFms=this.modelForms;
                const names=this.namess;
                if (modelFms.length!==0){
                    if (names.indexOf(somedata.name)==-1){//不存在
                        names.push(somedata.name);
                        modelFms.push(somedata);
                    }else{//已存在
                        modelFms = modelFms.filter(item => {
                            return item.name != somedata.name;
                        });
                        modelFms.push(somedata);
                    }
                }else{
                    names.push(somedata.name);
                    modelFms.push(somedata);
                };
                this.namess=names;
                //进行排序
                for (let i = 0; i <modelFms.length; i++) {
                    for(let j=0;j<modelFms.length-i-1;j++){
                        if(modelFms[j].name>modelFms[j+1].name){
                            let temp=modelFms[j];
                            modelFms[j]=modelFms[j+1];
                            modelFms[j+1]=temp;
                        }
                    }
                };
                this.modelForms = modelFms;
            },
            //弹出评估弹出框
            goAssess(index, row){
                this.assesstableTabsValue='1';
                this.assesstabIndex=1;
                this.condition.ptId=row.ptId;
                this.assesstableTabs=[
                    {
                        title: '关节活动度评估',
                        name: '1',
                        content:'assessOneModel'
                    },
                    {
                        title: '肌力评估',
                        name: '2',
                        content:'assessTwoModel'
                    },
                    {
                        title: 'Brunnstrom评估',
                        name: '3',
                        content:'assessThreeModel'
                    },
                    {
                        title: 'Ashworth评估',
                        name: '4',
                        content:'assessForeModel'
                    }
                ];
                this.assessptId=row.ptId;
                this.assessptNm=row.ptNm;
                this.assessptSexText=row.ptSexText;
                this.assessVisible=true;
            },
            //关闭评估弹出框
            assessColse(){
                this.$confirm('确认关闭？', '提示', {
                    type: 'warning'
                })
                    .then(() => {
                        this.assesstableTabs=[];
                        this.assessnamess=[];
                        this.assessModels=[];
                        this.assessVisible=false;
                    })
                    .catch(() => {
                        this.$message({
                            message:'已取消操作'
                        });
                    });

            },
            //提交评估信息
            saveAssess(){
                //判断如果四项评估都填写完成，保存到后台
                const names=[];
                if (this.assessModels.length>0) {
                    for (let i = 0; i < this.assessModels.length; i++) {
                        names.push(this.assessModels[i].name);
                    };
                    if (names.indexOf("1")==-1){
                        this.$message.error('请保存第一页签：关节活动度评估');
                        return;
                    };
                    if (names.indexOf("2")==-1){
                        this.$message.error('请保存第二页签：肌力评估');
                        return;
                    };
                    if (names.indexOf("3")==-1){
                        this.$message.error('请保存第三页签：Brunnstrom评估');
                        return;
                    };
                    if (names.indexOf("4")==-1){
                        this.$message.error('请保存第四页签：Ashworth评估');
                        return;
                    };
                    //4个页签全部存在 调用后台 保存评估数据
                    const result={
                        ptId:this.condition.ptId,
                        assHipMin:this.assessModels[0].assHipMin,
                        assHipMax:this.assessModels[0].assHipMax,
                        assKneeMin:this.assessModels[0].assKneeMin,
                        assKneeMax:this.assessModels[0].assKneeMax,
                        assAnkleMin:this.assessModels[0].assAnkleMin,
                        assAnkleMax:this.assessModels[0].assAnkleMax,
                        assMuscle:this.assessModels[1].assMuscle,
                        assBrunstrom:this.assessModels[2].assBrunstrom,
                        assAshworth:this.assessModels[3].assAshworth,
                        assCrtBy:localStorage.getItem('ms_userAcct'),
                    };
                    saveAssess(result).then(res => {
                        if (res.data == 1) {
                            this.assesstableTabs=[];
                            this.assessModels=[];
                            this.assessVisible=false;
                            this.$message.success('评估信息提交成功');
                        } else {
                            this.$message.error('评估信息提交失败');
                        }
                    });
                }else{
                    this.$message.error('未保存任何评估信息');
                }
            },
            //处理子组件传递数据(评估)
            handleassessFormData:function (somedata) {
                let modelFms=this.assessModels;
                const names=this.assessnamess;
                if (modelFms.length!==0){
                    if (names.indexOf(somedata.name)==-1){//不存在
                        names.push(somedata.name);
                        modelFms.push(somedata);
                    }else{//已存在
                        modelFms = modelFms.filter(item => {
                            return item.name != somedata.name;
                        });
                        modelFms.push(somedata);
                    }
                }else{
                    names.push(somedata.name);
                    modelFms.push(somedata);
                };
                this.assessnamess=names;
                //进行排序
                for (let i = 0; i <modelFms.length; i++) {
                    for(let j=0;j<modelFms.length-i-1;j++){
                        if(modelFms[j].name>modelFms[j+1].name){
                            let temp=modelFms[j];
                            modelFms[j]=modelFms[j+1];
                            modelFms[j+1]=temp;
                        }
                    }
                };
                this.assessModels = modelFms;
            },
            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, 'pageIndex', val);
                this.getData();
            },
            //幅度值 --
            downPreAmp(preId,preActionId,preActionAmplitude,i){
                if (preActionAmplitude<=99 && preActionAmplitude !==0){
                    //发送辐射指令 --
                    sendEleTrainReduce({preId:preId,preActionId:preActionId,preActionAmplitude:preActionAmplitude-1}).then(res => {
                        if (res.success==true){
                            this.$refs.PreAmp.value = preActionAmplitude-1;    // 给有 ref 属性的 input 赋值
                            this.preList[i].preActionAmplitude=preActionAmplitude-1;
                            console.log("幅度值--成功，值：",preActionAmplitude-1);
                        }else{
                            this.$message.error(res.data);
                        }
                    });
                }
            },
            //幅度值 ++
            upPreAmp(preId,preActionId,preActionAmplitude,i){
                //发送辐射指令 --
                if (preActionAmplitude==undefined || preActionAmplitude ==""){
                    sendEleTrainAdd({preId:preId,preActionId:preActionId,preActionAmplitude:1}).then(res => {
                        if (res.success==true){
                            this.$refs.PreAmp.value=1;
                            this.preList[i].preActionAmplitude=1;
                        }else{
                            this.$message.error(res.data);
                        }
                    });
                }else{
                    if (preActionAmplitude<99){
                        sendEleTrainAdd({preId:preId,preActionId:preActionId,preActionAmplitude:preActionAmplitude+1}).then(res => {
                            if (res.success==true){
                                this.$refs.PreAmp.value = parseInt(preActionAmplitude)+1;    // 给有 ref 属性的 input 赋值
                                this.preList[i].preActionAmplitude=parseInt(preActionAmplitude)+1;
                            }else{
                                this.$message.error(res.data);
                            }
                        });
                    }else {//超过99
                        sendEleTrainAdd({preId:preId,preActionId:preActionId,preActionAmplitude:99}).then(res => {
                            if (res.success==true){
                                this.$refs.PreAmp.value = 99;    // 给有 ref 属性的 input 赋值
                                this.preList[i].preActionAmplitude=99;
                            }else{
                                this.$message.error(res.data);
                            }
                        });
                    }
                }
                console.log("幅度值++成功，值：",this.preList[i].preActionAmplitude);
                // POST /api/stand/training/sendEleTrainAdd
            },
            proving1(e) {
                var keynum = window.event ? e.keyCode : e.which;   //获取键盘码
                var keychar = String.fromCharCode(keynum);  //获取键盘码对应的字符
                if (keynum ==189|| keynum==190||keynum == 109 || keynum == 110) {
                    this.$message.warning('禁止输入小数以及负数,请重新输入');
                    e.target.value = ' ';
                    return;
                }
                if (keynum==69){
                    this.$message.warning('禁止输入e或E');
                    e.target.value = ' ';
                    return;
                }
            },
            //总进度进度条展示
            format(percentage){
                let result=this.current+'/s';
                return percentage <=100 ? result:'';
            },
        }
    };
</script>
<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .table {
        width: 100%;
        font-size: 14px;
    }
    .red {
        color: #ff0000;
    }
    .mr10 {
        margin-right: 10px;
    }
    .schart {
        width: 550px;
        height: 300px;
    }
    .content-title {
        clear: both;
        font-weight: 400;
        line-height: 50px;
        margin: 10px 0;
        font-size: 22px;
        color: #1f2f3d;
    }
</style>
